package com.example.homework8.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.example.homework8.bean.UserInfo;


public class UserHelper extends SQLiteOpenHelper {
    private SQLiteDatabase mDB = null; // 数据库的实例


    private String DB_NAME ="user",DB_VERSION="1";
    private static final String LAN_USER = "create table user(name text,password text,classname text,phone text,imgurl text)";
    Context context;
    public UserHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
            super(context, name, factory, version);
            this.context = context;
    }
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(LAN_USER);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }

    // 根据条件更新指定的表记录
    public int update(UserInfo info, String condition) {
        ContentValues cv = new ContentValues();
        cv.put("classname", info.getClassname());
        cv.put("password", info.getPassword());
        cv.put("phone", info.getPhone());
        cv.put("imgurl", info.getImgurl());

        // 执行更新记录动作，该语句返回记录更新的数目
        return getWritableDatabase().update("user", cv, condition, null);
     }


}